package com.cskaoyan._01basic._05scanner;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            //定义用户名与密码
            String username = "admin";
            String password = "123456";

            //键盘录入
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名:");
            String name = sc.nextLine();
            System.out.println("请输入密码：");
            String pass = sc.nextLine();

            //登录判断
            if (name.equals(username) && pass.equals(password)) {
                System.out.println("登录成功~");
                break;
            } else {
                if (2-i== 0){
                    System.out.println("登录失败，你的账号已锁定！");
                }else {
                    System.out.println("登录失败，你还有" + (2 - i) + "次登录机会！");
                }
            }
        }
    }

}
